<template>
  <div id="o_getCoupon">
    <!-- hello world -->
    <magic-header titleName="优惠券" :returnNative="$route.params.native"></magic-header>
    <empty v-if="queryData.length === 0" message='当前没有可用的优惠券'></empty>
    <c-coupon :value="queryData" v-if="queryData.length !== 0" :limit="price" :isGetCou='true' v-on:getCoupon="getCoupon"></c-coupon>
  </div>
</template>

<script>
import magicHeader from "components/magicHeader";
import empty from "components/empty-page";
import ticket from "assets/pic_ticket_bg_y.png";
// import Order from 'services/order.service'
import cCoupon from "components/coupon";
import { getGetCouponInfo, receiveConpon } from "services/o_getCoupon.js";

// let order = Order.getInstance()
export default {
  name: "coupon",
  components: {
    cCoupon,
    magicHeader,
    empty
  },
  data() {
    return {
      ticket,
      queryData: [],
      price: ""
    };
  },
  created() {
    this.getGetCouponInfo();
  },
  methods: {
    getGetCouponInfo() {
      getGetCouponInfo.bind(this)(
        {
          promotionTypes: ["coupon"]
        },
        resp => {
          this.queryData = resp.promotions;
          console.log(this.queryData);
        }
      );
    },
    getCoupon(id) {
      if (this.$.userId) {
        receiveConpon.bind(this)(
          {
            couponId: id
          },
          resp => {
            this.$.toast("领取优惠券成功");
            this.getGetCouponInfo();
          },
          error => {
            this.$.toast(error);
            console.log(error);
          }
        );
      } else {
        this.$.goLogin({
          name: "login"
        });
      }
    }
  }
};
</script>
<style scoped>

</style>
